﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using System.Windows.Media;

namespace Dynamic_UI_Framework
{
    [Export(typeof(UserControlRegionAdapter))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    class UserControlRegionAdapter : AdapterBase<IRegion, UserControl>
    {
        protected override void Adapt(IRegion codon, UserControl target)
        {
            Region r = codon as Region;
            r.Target = target;
            target.Background = Brushes.Orange;

            target.ContextMenu = new ContextMenu();
            foreach (var item in r.GetMenuItem())
            {
                target.ContextMenu.Items.Add(item);
            }

            r.CurrentItemChanged += (s, e) =>
                {
                    target.Content = r.CurrentItem.Target;
                };
        }

        protected override IRegion Create()
        {
            return new Region();
        }
    }
}
